<?php

namespace app\common\validate;

class UserValidate extends BaseValidate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        'userpic' => 'image',
        'page' => 'require|integer|>:0',
        'id' => 'require|integer|>:0|isRefectId',
        'phone' => 'require|length:11',
        'code' => 'require|number|length:4|isPefectCode',
        'username' => 'require|length:6,16',
        'email' => 'require|email',
        'password' => 'require|alphaDash',
        'provider' => 'require',
        'openid' => 'require',
        'nickName' => 'require',
        'avatarUrl' => 'require',
        'expires_in' => 'require',
        'name' => 'require|chsDash',
        'sex' => 'require|in:0,1,2',
        'qg' => 'require|in:0,1,2',
        'job' => 'require|chsDash',
        'birthday' => 'require|dateFormat:Y-m-d',
        'path' => 'require|chsDash',
        'oldpassword' => 'require',
        'newpassword' => 'require|alphaDash',
        'renewpassword' => 'require|confirm:newpassword',
        'follow_id' => 'require|integer|>:0',
        'page' => 'require|integer|>:0'
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [
        'phone.require' => '请填写手机号',
        'phone.length' => '手机号不合法'
    ];

    // 配置场景
    protected $scene =  [
        'post' => ['id','page'],
        'postall' => ['page'],
        'sendcode' => ['phone'], //发送验证码
        'phonelogin' => ['phone','code'] ,  //手机号登陆
        //账号密码登录
        'login' => ['username','password'],
        // 第三方登陆
        'otherlogin' => ['provider','openid', 'nickName' , 'avatarUrl','expires_in'],
        // 绑定手机号
        'bindphone' => ['phone'] ,
        // 绑定邮箱
        'bindemail' => ['email'],
        // 上传头像
        'edituserpic' => ['userpic'],
        // 修改资料
        'edituserinfo' => ['name','sex','qg','job','birthday','path'],
        // 修改密码
        'repassword' => ['oldpassword','newpassword','renewpassword'],
        'follow' => ['follow_id'],
        'getfriends' => ['page'],
        'getfens' => ['page'],
        'getfollows' => ['page']
    ];
}
